<?php
/**
 * 用户
 * User: Acer
 * Date: 2022/2/3
 * Time: 20:48
 */

namespace app\admin\controller;

use app\admin\service\UserServide;
use app\core\MyController as MyController;

class User extends MyController
{

    protected $noNeedAction = []; // 不需要校验控制器，通道
    // 操作前置
    protected $beforeActionList = ['my_initialize'];

    // 操作前置方法
    public function my_initialize()
    {
//        $this->is_admin();  // 权限检查
    }

    // 获取用户列表
    public function get_list(){
        $data = input();
        // 页数
        if(!isset($data['page']))  json_err( -201);
        // 当前页数
        if(!isset($data['page_number'])) $data['page_number'] = 10;
        // 查询
        $like =[];
        // 用户名称
        if( isset($data['username']) && $data['username'] ) $like['username'] = $data['username'];
        // 账号
        if( isset($data['mobile']) && $data['mobile'] ) $like['mobile'] = $data['mobile'];
        // 身份证
        if( isset($data['id_card']) && $data['id_card'] ) $like['id_card'] = $data['id_card'];

        $res = (new UserServide())->s_user_list($data['page'],$data['page_number'],$like);
        if($res) _action_result(200,$res,'操作成功！');
        json_err( -205);
    }
    // 根据用户id，获取卡片列表
    public function get_user_card_list(){
        $data = input();
        // 页数
        if(empty($data['uid']))  json_err( -201);
        $res = (new UserServide())->s_get_user_card_list($data['uid']);
         _action_result(200,$res,'操作成功！');
    }


    // 修改用户信息
    public function modify_user(){
        $data = input();
        if(empty($data['did']) || empty($data['mobile']) || empty($data['name']) || empty($data['id_card']) ) json_err( -201);
        $UserServide = new UserServide();
        $UserServide->s_modify_user($data);
        _action_result(200,[],'操作成功！');
    }


    // 根据用户id，删除用户
    public function del_user(){
        $data = input();
        // 页数
        if(empty($data['uid']))  json_err( -201);
        $res = (new UserServide())->del_user($data['uid']);
         _action_result(200,$res,'操作成功！');
    }

    // 添加黑名单
    public function add_blacklist() {
        $data = input();
        if(empty($data['id_card']))  json_err( -201);
        $res = (new UserServide())->add_blacklist($data);
        _action_result(200,$res,'操作成功！');
    }

    // 黑名单列表
    public function blacklist() {
        $data = input();
        // 页数
        if(!isset($data['page']))  json_err( -201);
        // 当前页数
        if(!isset($data['page_number'])) $data['page_number'] = 10;
        // 查询
        $like =[];
        // 身份证
        if( isset($data['id_card']) && $data['id_card'] ) $like['id_card'] = $data['id_card'];

        $res = (new UserServide())->blacklist($data['page'],$data['page_number'],$like);
        if($res) _action_result(200,$res,'操作成功！');
        json_err( -205);
    }

    // 修改黑名单
    public function modify_blacklist() {
        $data = input();
        if(empty($data['did']) || empty($data['id_card']) ) json_err( -201);
        $UserServide = new UserServide();
        $UserServide->modify_blacklist($data);
        _action_result(200,[],'操作成功！');
    }

    // 删除黑名单
    public function delete_blacklist() {
        $data = input();
        if(empty($data['did'])) json_err( -201);
        $UserServide = new UserServide();
        $UserServide->delete_blacklist($data);
        _action_result(200,[],'操作成功！');
    }
}